<template>
  <div class="emailLogin_container">
    <van-nav-bar
			left-arrow
			@click-left="onClickLeft"
			@click-right="onClickRight"
		>
		<template #right>
			<!-- <van-icon name="search" size="18" /> -->
			 <span>{{$t("注册")}}</span>
		</template>
		</van-nav-bar>
		<div class="emailLogin_container_body padding-1">
			<div class="emailLogin_container_card br-16 padding-1">
				<p class="mb-0">{{$t("邮箱地址")}}</p>
				<input class="mb-0" type="text" v-model="email">
				<p class="mb-0">{{$t("密码")}}</p>
				<input class="mb-0" type="password" v-model="password">
				<div class="card_label mb-2" @click="forgetPassword">{{$t("忘记密码")}}</div>
				<button @click="doLogin">{{$t("登录")}}</button>
			</div>
		</div>
  </div>
</template>

<script>
import { loginNew } from "@/request/login"
export default {
	name: 'EmailLogin',
	data(){
			return{
				email:'',
				password:'',
			}
	},
	mounted(){},
	methods:{
		onClickLeft(){
			this.$router.go(-1)
		},
		onClickRight(){
			// 前往注册
			if(this.$route.name !== 'RegisterAccount'){
				this.$router.push({
					name:'RegisterAccount'
				})
			}
		},
		doLogin(){
			// 点击登录
			if(!!this.email && !!this.password){
				let obj = {
					account:this.email,
					password:this.password,
					type: 2,
				}
				loginNew(obj).then(res=>{
					if(res.code === 1){
						let { token } = res.data.userinfo
						localStorage.setItem('token', token)
						localStorage.setItem('imToken', res.data.im_token)
						localStorage.setItem('im_userinfo', JSON.stringify(res.data.im_userinfo))
						localStorage.setItem('address', this.walletAddress)
						this.$toast.success(this.$t("登录成功"))
						this.$router.push({name:'HomePage'})
					}else{
						this.$toast.fail(res.msg)
						this.$router.push({name:'RegisterAccount'})
					}
				})
			}else{
				this.$toast.fail(this.$t("请输入邮箱和密码"))
			}
		},
		forgetPassword(){
			// 忘记密码
			if(this.$route.name !== 'ForgetPassword'){
				this.$router.push({
					name:'ForgetPassword'
				})
			}
		}
	}
}
</script>

<style>

</style>